//
//  MydataEditViewController.m
//  ShangHaiTuJI
//
//  Created by xiaoxiangtuji on 2017/8/17.
//  Copyright © 2017年 xiaoxiangtuji. All rights reserved.
//

#import "MydataEditViewController.h"
#import "GFDatePicker.h"
#import "GFAddressPicker.h"
#import "GFSexView.h"
#import "BRTextField.h"
#import "EditBottomCell.h"
#import "EditDataListCell.h"
#import "InstituTypeChooseView.h"
@interface MydataEditViewController ()<UITableViewDelegate,UITableViewDataSource,GFAddressPickerDelegate,GetBabySexInformation,UITextFieldDelegate,UIImagePickerControllerDelegate,UIActionSheetDelegate,UIViewControllerTransitioningDelegate,UITextViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
/** 姓名 */
@property (nonatomic, strong) BRTextField *nameTF;
@property (nonatomic, strong) BRTextField *assignTF;
@property(nonatomic,strong)UIImageView *imageView;
@property(nonatomic,strong)UITableView *tablview;
@property(nonatomic,strong)NSArray *titleArray;
@property(nonatomic,copy)NSString *time;
@property(nonatomic,strong)GFAddressPicker *pickerView;
@property(nonatomic,strong)GFSexView *sexView;
@property(nonatomic,strong)UIButton *saveBtn;
@property(nonatomic,copy)NSString *sexs;
@property(nonatomic,strong)UIActionSheet *actionSheet;
@property(nonatomic,copy)NSString *pictureId;
@property(nonatomic,strong)NSArray *labelArray;

@property(nonatomic,strong)UICollectionView *collectionView;
@property(nonatomic,strong)UICollectionViewFlowLayout *fowLayout;
@property(nonatomic,strong)NSMutableArray *labelStrArray;
@property(nonatomic,strong)InstituTypeChooseView *shareView;
@property(nonatomic,strong)UIView *backView;
@property(nonatomic,strong)NSMutableArray *chooseShowArray;
@property(nonatomic,strong)NSMutableArray *valuesArray;
@end

@implementation MydataEditViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self createSaveBtn];
    [self createNavagationBackBtn];
    self.title = @"资料编写";
    [self createTableViewUI];
    // Do any additional setup after loading the view.
}
-(void)createSaveBtn{
    self.saveBtn= [UIButton buttonWithType:UIButtonTypeCustom];
    self.saveBtn.frame = CGRectMake(20, 0, 60, 30);
    [self.saveBtn addTarget:self action:@selector(savePersonalData:) forControlEvents:UIControlEventTouchUpInside];
    [self.saveBtn setTitle:@"保存" forState:UIControlStateNormal];
    [self.saveBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    UIBarButtonItem *flexSpac = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:self action:nil];
    flexSpac.width = -10;
    UIBarButtonItem *rightBar = [[UIBarButtonItem alloc] initWithCustomView:self.saveBtn];
    self.navigationItem.rightBarButtonItems = @[flexSpac,rightBar];
}
-(void)savePersonalData:(UIButton *)btn{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    NSString *sessionID = [[NSUserDefaults standardUserDefaults] objectForKey:@"sessionId"];
    EditBottomCell *cell = [self.tablview cellForRowAtIndexPath:[NSIndexPath indexPathForRow:6 inSection:0]];
    UITableViewCell *cell3 = [self.tablview cellForRowAtIndexPath:[NSIndexPath indexPathForRow:4 inSection:0]];
    NSString *url = ServerIp@"/customerApp/editCustomer";
    NSString *labelss = [self.labelStrArray componentsJoinedByString:@","];
    NSLog(@"数组元素%@",labelss);
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSDate *date = [dateFormatter dateFromString:cell3.detailTextLabel.text];
    
    NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[date timeIntervalSince1970]];
    NSLog(@"时间戳%@",timeSp);
    NSDictionary *param = [NSDictionary dictionaryWithObjectsAndKeys:self.nameTF.text,@"name",self.sexs,@"gender",self.assignTF.text,@"autograph",self.pictureId,@"picId",sessionID,@"sessionId",labelss,@"interest",timeSp,@"birthday",nil];
    NSLog(@"数组的值%@",param);
    [manager POST:url parameters:param progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        NSLog(@"%@",jsonDic[@"msg"]);
        NSLog(@"%@",jsonDic);
        
        self.personBlock(param,self.imageView.image);
         [self.navigationController popViewControllerAnimated:YES];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"失败%@",error);
    }];
   
}

//-(void)createNavagationBackBtn{
//    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    backBtn.frame = CGRectMake(0, 6, 67, 23);
//    UIImageView *backImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"navigator_btn_back"]];
//    backImg.frame = CGRectMake(-10, 0, 22, 22);
//    [backBtn addSubview:backImg];
//    UILabel *backText = [[UILabel alloc] initWithFrame:CGRectMake(12, 0, 65, 22)];
////    backText.text = @"返回";
//    backText.font = [UIFont systemFontOfSize:17];
//    [backText setBackgroundColor:[UIColor clearColor]];
//    [backText setTextColor:[UIColor whiteColor]];
//    [backBtn addSubview:backText];
//    [backBtn addTarget:self action:@selector(leftBarButtonItemPressed:) forControlEvents:UIControlEventTouchUpInside];
//    [backImg mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(backBtn.mas_left).offset(-10);
//        make.centerY.equalTo(backBtn.mas_centerY);
//        make.size.mas_equalTo(CGSizeMake(22, 22));
//    }];
//    [backText mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(backImg.mas_right).offset(2);
//        make.centerY.equalTo(backBtn.mas_centerY);
//        make.size.mas_equalTo(CGSizeMake(65, 22));
//    }];
//    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
//    [self.navigationItem setLeftBarButtonItem:leftButton];
//}
//-(void)leftBarButtonItemPressed:(UIButton *)btn{
////    [self dismissViewControllerAnimated:YES completion:nil];
//    [self.navigationController popViewControllerAnimated:YES];
//}

/**
 初始化tablview
 */
-(void)createTableViewUI{
    self.tablview = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, WIDTH, 350) style:UITableViewStylePlain];
    [self.view addSubview:self.tablview];
    self.tablview.scrollEnabled = NO;
    self.tablview.delegate = self;
    self.tablview.dataSource = self;
    UIView *footerView = [[UIView alloc] init];
    self.tablview.tableFooterView = footerView;
    [self.tablview registerClass:[EditBottomCell class] forCellReuseIdentifier:@"EditBottomCell"];
//    [self createCollectionViewInFathreView];
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.titleArray.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellId = @"CellID";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellId];
    }
    cell.textLabel.text = self.titleArray[indexPath.row];
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    if (indexPath.row == 0) {
        cell.accessoryType = UITableViewCellAccessoryNone;
        [self addImageView:cell];
        
    }
    if (indexPath.row == 1) {
        cell.accessoryType = UITableViewCellAccessoryNone;
        [self setupNameTF:cell];
    }
    if (indexPath.row == 2) {
        cell.accessoryType = UITableViewCellAccessoryNone;
       [self setupAssignTF:cell];
    }
    if (indexPath.row == 6) {
        cell.detailTextLabel.text = @"最多选择3个";
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50.f;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    switch (indexPath.row) {
        case 0:
        {

        }
            break;
        case 1:
        {
            
        }
            break;
        case 2:
        {
            
        }
            break;
        case 3:
        {
            self.sexView = [[GFSexView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
            self.sexView.delegate = self;
            [self.view addSubview:self.sexView];
            
        }
            break;
        case 4:
        {
            [GFDatePicker showCustomDatePickerAtView:self.view choosedDateBlock:^(NSDate *date) {
                UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
                NSString *dateStr = [NSString stringWithFormat:@"%@",date];
                cell.detailTextLabel.text = [dateStr componentsSeparatedByString:@" "][0];
            } cancelBlock:^{
                
            }];
        }
            break;
        case 5:
        {
            self.pickerView = [[GFAddressPicker alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
            [self.pickerView updateAddressAtProvince:@"河南省" city:@"郑州市" town:@"金水区"];
            self.pickerView.delegate = self;
            self.pickerView.font = [UIFont boldSystemFontOfSize:18];
            [self.view addSubview:self.pickerView];
        }
            break;
        case 6:
        {
            [self showChooseTypeUI];
        }
            break;
        default:
            break;
    }
}
-(void)createCollectionViewInFathreView{
    self.fowLayout = [[UICollectionViewFlowLayout alloc] init];
    self.fowLayout.minimumInteritemSpacing = scaleLeftAndRight(10);
    self.fowLayout.minimumLineSpacing = scaleTopAndBottom(20);
    self.fowLayout.itemSize = CGSizeMake(scaleTopAndBottom(85), scaleTopAndBottom(25));
    self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:self.fowLayout];
    self.collectionView.backgroundColor = [UIColor whiteColor];
    self.collectionView.allowsMultipleSelection = YES;
    [self.view addSubview:self.collectionView];
    [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.top.equalTo(self.tablview.mas_bottom);
        make.bottom.equalTo(self.view.mas_bottom);
    }];
    [self.collectionView registerClass:[EditDataListCell class] forCellWithReuseIdentifier:@"EditDataListCell"];
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 9;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    EditDataListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"EditDataListCell" forIndexPath:indexPath];
     cell.label.text = self.labelArray[indexPath.row];
    return cell;
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    EditDataListCell *cell = (EditDataListCell *)[collectionView cellForItemAtIndexPath:indexPath];
    NSIndexPath *index = [NSIndexPath indexPathForRow:6 inSection:0];
    UITableViewCell *cells = [self.tablview cellForRowAtIndexPath:index];
    if (self.labelStrArray.count >=3) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"标签最多三个" message:nil delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alertView show];
    }else{
        [self.labelStrArray addObject:cell.label.text];
        cell.label.layer.borderColor = COLOR_HEX(0xffc91f).CGColor;
        cell.label.textColor = COLOR_HEX(0xffc91f);
        NSString *labeStr = @"";
        for (NSInteger i = 0; i < self.labelStrArray.count; i++) {
            NSString *str = [NSString stringWithFormat:@" %@",self.labelStrArray[i]];
            labeStr = [labeStr stringByAppendingString:str];
        }
        cells.detailTextLabel.text = labeStr;
    }

}
-(void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath{
    EditDataListCell *cell = (EditDataListCell *)[collectionView cellForItemAtIndexPath:indexPath];
    cell.label.layer.borderColor = [UIColor blackColor].CGColor;
    cell.label.textColor = [UIColor blackColor];
    [self.labelStrArray removeObject:cell.label.text];
    NSString *labeStr = @"";
    NSIndexPath *index = [NSIndexPath indexPathForRow:6 inSection:0];
    UITableViewCell *cells = [self.tablview cellForRowAtIndexPath:index];
    for (NSInteger i = 0; i < self.labelStrArray.count; i++) {
        NSString *str = [NSString stringWithFormat:@" %@",self.labelStrArray[i]];
        labeStr = [labeStr stringByAppendingString:str];
        
    }
    cells.detailTextLabel.text = labeStr;
    if (self.labelStrArray.count == 0) {
        cells.detailTextLabel.text = @"标签最多三个";
    }
}
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    return UIEdgeInsetsMake(scaleTopAndBottom(35), scaleLeftAndRight(35), scaleTopAndBottom(35), scaleLeftAndRight(35));
}
-(NSMutableArray *)labelStrArray{
    if (_labelStrArray == nil) {
        _labelStrArray = [[NSMutableArray alloc] init];
    }
    return _labelStrArray;
}

-(NSArray *)labelArray{
    if (_labelArray == nil) {
        _labelArray = @[@"舞蹈",@"朗诵",@"乐器",@"表演",@"戏曲",@"主持",@"手法",@"唱歌",@"棋类"];
    }
    return _labelArray;
}
#pragma mark -地址的代理方法
- (void)GFAddressPickerCancleAction
{
    [self.pickerView removeFromSuperview];
}

- (void)GFAddressPickerWithProvince:(NSString *)province
                               city:(NSString *)city area:(NSString *)area
{
    [self.pickerView removeFromSuperview];
    NSIndexPath *indexpath = [NSIndexPath indexPathForRow:5 inSection:0];
    UITableViewCell * cell = [self.tablview cellForRowAtIndexPath:indexpath];
    cell.detailTextLabel.text = [NSString stringWithFormat:@"%@  %@  %@",province,city,area];
    
    NSLog(@"%@  %@  %@",province,city,area);
}
#pragma mark -性别的代理方法
-(void)getBabySexInformation:(NSString *)sex{
    [self.sexView removeFromSuperview];
    NSIndexPath *indexpath = [NSIndexPath indexPathForRow:3 inSection:0];
    UITableViewCell * cell = [self.tablview cellForRowAtIndexPath:indexpath];
    cell.detailTextLabel.text = sex;
    if ([sex isEqual:@"男宝宝"]) {
        self.sexs = @"true";
    }else{
        self.sexs = @"false";
    }
}
-(void)GFBabySexPickerCancleAction{
    [self.sexView removeFromSuperview];
}
- (BRTextField *)getTextField:(UITableViewCell *)cell {
    BRTextField *textField = [[BRTextField alloc]initWithFrame:CGRectMake(WIDTH/3, 0, WIDTH/2, 50)];
    textField.backgroundColor = [UIColor clearColor];
    textField.font = [UIFont systemFontOfSize:16.0f];
    textField.textAlignment = NSTextAlignmentLeft;
    textField.delegate = self;
    [cell.contentView addSubview:textField];
    return textField;
}
-(void)addImageView:(UITableViewCell *)cell{
    self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH - 60, 5, 40, 40)];
    self.imageView.image = [UIImage imageNamed:@"DefaultICon"];
    self.imageView.userInteractionEnabled = YES;
    self.imageView.layer.cornerRadius = 20;
    self.imageView.layer.masksToBounds = YES;
    self.imageView.backgroundColor = [UIColor cyanColor];
    [cell.contentView addSubview:self.imageView];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gotoPickPicture:)];
    [self.imageView addGestureRecognizer:tap];
}
#pragma mark - 姓名 textField
- (void)setupNameTF:(UITableViewCell *)cell {
    if (!_nameTF) {
        _nameTF = [self getTextField:cell];
        _nameTF.placeholder = @"请输入";
//        _nameTF.font = [UIFont systemFontOfSize:15];
        _nameTF.returnKeyType = UIReturnKeyDone;
        _nameTF.tag = 0;
    }
}
-(void)setupAssignTF:(UITableViewCell *)cell{
    if (!_assignTF) {
        _assignTF = [self getTextField:cell];
        _assignTF.placeholder = @"请输入";
        //        _nameTF.font = [UIFont systemFontOfSize:15];
        _assignTF.returnKeyType = UIReturnKeyDone;
        _assignTF.tag = 4;
    }
}
#pragma mark - UITextFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    if (textField.tag == 0 || textField.tag == 4) {
        [textField resignFirstResponder];
    }
    return YES;
}
-(BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    if ([text isEqualToString:@"\n"]) {
        [textView resignFirstResponder];
        return NO;
    }
    return YES;
}
-(NSArray *)titleArray{
    if (_titleArray == nil) {
        _titleArray = @[@"头像",@"昵称",@"个性签名",@"性别",@"生日",@"地区",@"兴趣爱好"];
    }
    return _titleArray;
}
#pragma mark -点击上传图片的手势
-(void)gotoPickPicture:(UITapGestureRecognizer *)tap{
    if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
        self.actionSheet = [[UIActionSheet alloc] initWithTitle:@"选择图像" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"拍照", @"从相册选择",  nil];
    }else{
        self.actionSheet = [[UIActionSheet alloc] initWithTitle:@"选择图像" delegate:self cancelButtonTitle:@"取消"destructiveButtonTitle:nil otherButtonTitles:@"从相册选择", nil];
    }
    self.actionSheet.tag = 10000;
    [self.actionSheet showInView:self.view];
    
}
#pragma mark - 调用相机的代理方法
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (actionSheet.tag == 10000) {
        NSUInteger sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        // 判断是否支持相机
        if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
            switch (buttonIndex) {
                case 0:
                    //来源:相机
                    sourceType = UIImagePickerControllerSourceTypeCamera;
                    break;
                case 1:
                    //来源:相册
                    sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
                    break;
                case 2:
                    return;
            }
        }
        else {
            if (buttonIndex == 2) {
                return;
            } else {
                sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
            }
        }
        // 跳转到相机或相册页面
        UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
        imagePickerController.delegate = (id)self;
        imagePickerController.allowsEditing = YES;
        imagePickerController.sourceType = sourceType;
        imagePickerController.transitioningDelegate = self;
        imagePickerController.modalPresentationStyle = UIModalPresentationCustom;
        [self presentViewController:imagePickerController animated:YES completion:nil];
    }
}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
    [self dismissViewControllerAnimated:YES completion:nil];
    NSLog(@"%@",[info objectForKey:UIImagePickerControllerReferenceURL]);
    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
    self.imageView.image = image;
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    NSString *url = PictureIp@"/file/fileUpload";
    [manager POST:url parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        NSData *imageData = UIImagePNGRepresentation(image);
        [formData appendPartWithFileData:imageData name:@"file" fileName:@"producction.png" mimeType:@"application/octet-stream"];
    } progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        self.pictureId = dict[@"id"];
        NSLog(@"获取到的数据%@",dict);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
}

/**
 显示类型爱好的选择
 */
-(void)showChooseTypeUI{
    self.backView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    _backView.alpha = 0.5f;
    _backView.backgroundColor = [UIColor blackColor];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(removessbackView:)];
    [_backView addGestureRecognizer:tap];
    [[UIApplication sharedApplication].keyWindow addSubview:_backView];
    _shareView = [[InstituTypeChooseView alloc] initWithFrame:CGRectMake(10, HEIGHT, WIDTH - 20, HEIGHT - 30)];
    __weak typeof(self) weakself = self;
    _shareView.valuesStrBlock = ^(NSString *valuesStr) {
        __strong typeof(self) strongself = weakself;
        [strongself.backView removeFromSuperview];
        NSIndexPath *index = [NSIndexPath indexPathForRow:6 inSection:0];
        UITableViewCell *cells = [weakself.tablview cellForRowAtIndexPath:index];
        cells.detailTextLabel.text = valuesStr;
    };
    _shareView.closeViewBlock = ^{
        __strong typeof(self) strongself = weakself;
        [strongself.backView removeFromSuperview];
        NSLog(@"璇去到的%@",strongself.shareView.chooseDataArray);
        NSArray *array = [strongself backNewArray:strongself.shareView.chooseDataArray];
        NSLog(@"传递过来的所有key%@",array);
        strongself.chooseShowArray = [strongself bckeAllChooseDateWithNewArray:array];

        NSLog(@"你要的键值对%@",strongself.shareView.vlauesAndIdsArray);
        for (NSInteger i = 0; i < strongself.shareView.vlauesAndIdsArray.count; i++) {
            NSDictionary *dict = strongself.shareView.vlauesAndIdsArray[i];
//            NSLog(@"小字典%@",dict);
            NSLog(@"选去过啦%@",strongself.chooseShowArray);
            NSLog(@"%@",strongself.chooseShowArray[0]);
            NSLog(@"哈哈哈哈%@",[dict allValues][0]);

            NSLog(@"所有信息%@",strongself.chooseShowArray);

            for (NSDictionary *dicss in strongself.chooseShowArray) {
                NSArray *valueArra = [dicss allValues];
                for (NSInteger i = 0; i < valueArra.count; i++) {
                    [strongself.valuesArray addObject:valueArra[i]];
                }
//                [strongself.valuesArray  addObject:[dicss allValues]];
            }
            NSLog(@"所有信息%@",strongself.valuesArray);
            NSString *labeStr = @"";
            for (NSInteger i = 0; i < self.valuesArray.count; i++) {
                NSString *str = [NSString stringWithFormat:@" %@",strongself.valuesArray[i]];
                labeStr = [labeStr stringByAppendingString:str];
            }
//            NSIndexPath *index = [NSIndexPath indexPathForRow:6 inSection:0];
//            UITableViewCell *cells = [strongself.tablview cellForRowAtIndexPath:index];
//            cells.detailTextLabel.text = labeStr;

            for (NSInteger j = 0; j < strongself.shareView.chooseDataArray.count; j++) {
                NSDictionary *vlaueDic = strongself.shareView.chooseDataArray[j];
                NSString *valueee = [vlaueDic allValues][0];
                if ([valueee isEqual:[dict allValues][0]]) {
                }
            }
        }
    };

    [[UIApplication sharedApplication].keyWindow addSubview:_shareView];
    [UIView animateWithDuration:0.1 animations:^{
        _shareView.frame = CGRectMake(10, HEIGHT - (HEIGHT - 30), WIDTH - 20, HEIGHT - 30);
    }];
}
-(NSArray *)backNewArray:(NSMutableArray *)arra{
    NSMutableArray *keysArra = [[NSMutableArray alloc] init];
    for (NSInteger i = 0; i < arra.count; i++) {
        NSDictionary *dic = arra[i];
        [keysArra addObject:[dic allKeys][0]];
    }
    NSSet *set = [NSSet setWithArray:keysArra];
    return   [set allObjects];
}
-(NSMutableArray *)bckeAllChooseDateWithNewArray:(NSArray *)arr{
    NSMutableArray *backArray = [[NSMutableArray alloc] init];
    for (NSInteger i = 0; i < arr.count; i++) {
        NSString *key = arr[i];
        NSMutableDictionary *dictt = [[NSMutableDictionary alloc] init];
        NSMutableArray *arra = [[NSMutableArray alloc] init];
        
        for (NSInteger j = 0; j < self.shareView.chooseDataArray.count; j++) {
            NSDictionary *dic = self.shareView.chooseDataArray[j];
            NSLog(@"哲哲字典%@",dic);
            if ([[dic allKeys][0] isEqual:key]) {
                [arra addObject:[dic allValues][0]];
            }
            
        }
        NSLog(@"这哲哲%@",arra);
        [dictt setObject:arra forKey:key];
        [backArray addObject:dictt];
    }
    return backArray;
}
-(void)sendAllDataValue:(UIButton *)btn{
    NSLog(@"获取到的所有数据%@",_shareView.chooseDataArray);
    [UIView animateWithDuration:0.1 animations:^{
        [_backView removeFromSuperview];
        [_shareView removeFromSuperview];
    }];
    
}
-(void)removessbackView:(UITapGestureRecognizer *)tap{
    [UIView animateWithDuration:0.1 animations:^{
        UIView *view = tap.view;
        [view removeFromSuperview];
        [_shareView removeFromSuperview];
    }];
}
-(NSMutableArray *)chooseShowArray{
    if (_chooseShowArray == nil) {
        _chooseShowArray = [[NSMutableArray alloc] init];
    }
    return _chooseShowArray;
}
-(NSMutableArray *)valuesArray{
    if (_valuesArray == nil) {
        _valuesArray = [[NSMutableArray alloc] init];
    }
    return _valuesArray;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
